package cn.dansj.handler.interfaces;

import cn.dansj.annotation.MarkAsApi;
import cn.dansj.common.utils.enums.ResponseCode;
import cn.dansj.common.utils.transfer.Transformation;
import cn.dansj.common.utils.transfer.Verification;
import cn.dansj.exception.InterfaceResponseException;
import cn.dansj.handler.InterfaceHandler;

import java.util.Map;

@MarkAsApi
public class EdgeUpdateComponentProps extends InterfaceHandler {
    private static final String update = "update x_edge_component set component=? ,height=? ,width=? ,`show`=? ,title=? ,url=? ,prop=? where id=?";

    @Override
    public Object execute(Map<String, Object> paramsMap) {
        String component = Transformation.toString(paramsMap.get("component"));
        int height = Transformation.parseInt(paramsMap.get("height"));
        int width = Transformation.parseInt(paramsMap.get("width"));
        String id = Transformation.toString(paramsMap.get("id"));
        int show = Transformation.transBooleanToInt(Transformation.castToBoolean(paramsMap.get("show")));
        String title = Transformation.toString(paramsMap.get("title"));
        String url = Transformation.toString(paramsMap.get("url"));
        String prop = Transformation.toString(paramsMap.get("prop"));
        if (Verification.checkNull(id) || jdbcTemplate.update(update, component, height, width, show, title, url, prop, id) == 0) {
            throw new InterfaceResponseException(ResponseCode.Error.getStatusCode(), "未找到组件");
        }
        return true;
    }
}